/* 编写C程序提取下列字符串中的目录名，
 * 文件名和后缀名为 c:\windows\path\networks.docx         
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char s[] = "c:\\windows\\path\\networks.docx";
    char *p = s;
    char *p1 = s;
    char buf[1024] = {0};
    while (p1 != NULL)
    {
        p1 = strstr(p, "\\");
        if (p1 != NULL)
            p = p1 + 1;
    }
    memcpy(buf, s, p - s - 1);
    printf("path=%s\n", buf);
    p1 = strstr(p, ".");
    memset(buf, 0, sizeof(buf));
    memcpy(buf, p, p1 - p);
    printf("filename=%s\n", buf);

    memset(buf, 0, sizeof(buf));
    strcpy(buf, p1 + 1);
    printf("fileEXT=%s\n", buf);

    return 0;
}
/*运行结果：path =  c:\windows\path
           filename = networks
           fileEXT = docx   
*/